slugify.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 13
rs 9.4285
1
import {toLowerCase, trim, removeSpaces, replace, transliterate} from './strman';
2
3
/**
4
 * Converts a value to a slug.
5
 * @playground
6
 * var slugify = require('strman').slugify;
7
 * let title = "A Javascript string manipulation library.";
8
 * let result = slugify(title);
9
 * @param {String} value - The value to slugify
10
 * @return {String} - The slugified value
11
 */
12
const slugify = (value) => {
13
14
    let result = value;
15
    result = toLowerCase(result);
16
    result = trim(result);
17
    result = removeSpaces(result, '-');
18
    result = replace(result, '&','-and-');
19
    result = transliterate(result);
20
    result = replace(result, '[^\\w\\-]+', '');
21
    result = replace(result, '\-\-+','-');
22
23
    return result;
24
};
25
26
export {slugify};
27